<?php
/**
 * 汎用ユーティリティクラス
 * 
 * 1.0 2011.03.17 初期リリース
 * 
 * @filesource Utility.class.php
 * @package forty-two
 * @subpackage forty-two
 * @version 1.0
 */



/**
 * ユーティリティクラス
 * 
 * 1.0 2011.03.17 初期リリース
 * 
 * @author koto
 * @package forty-two
 * @version 1.0
 */
class Utility
{
    /**
     * var_dump結果文字列取得処理
     * 
     * @since 1.0
     * @access static
     * @param mixi  $vars    変数
     * @param string
     */
    static function ddump($vars = NULL, $html = TRUE)
    {
        $dbtAll = debug_backtrace();
        $dbt = $dbtAll[0];
        $str = NULL;
        $time = NULL;
        
        $dbt['line'] = isset($dbt['line'])?$dbt['line']:$dbtAll[1]['line'];
        $dbt['file'] = isset($dbt['file'])?$dbt['file']:$dbtAll[1]['file'];
        $dbt['file'] = basename($dbt['file']);
        
        $str = CU::cdump($vars);
        $time = CU::getExecTime();
        if ($html) {
            $str = sprintf('%s(%s) time(%s) %s<br />', $dbt['file'], $dbt['line'], $time, $str);
        } else {
            $str = sprintf('%s(%s) time(%s) %s', $dbt['file'], $dbt['line'], $time, $str);
        }
        
        echo $str;
    }
    
    /**
     * var_dump結果文字列取得処理
     * 
     * @since 1.0
     * @access static
     * @param mixi  $vars    変数
     * @param string
     */
    static function tdump($vars = NULL, $dispTraceNo = 5)
    {
        $dbtAll = debug_backtrace();
        $dbt = $dbtAll[0];
        $str = NULL;
        $time = NULL;
        
        $dbt['line'] = isset($dbt['line'])?$dbt['line']:$dbtAll[1]['line'];
        $dbt['file'] = isset($dbt['file'])?$dbt['file']:$dbtAll[1]['file'];
        $dbt['file'] = basename($dbt['file']);
        
        $trace = Error::_getTraceData($dispTraceNo);
        
        $str = CU::cdump($vars);
        $time = CU::getExecTime();
        
        $data = sprintf('%s(%s) time(%s) %s<br />', $dbt['file'], $dbt['line'], $time, $str);
        
        // テーブル化出来るよう整形
        $tableArr['option'] = array('type' => 'table', 'setting' => 'border="1"');
        $tableArr[] = array(
                        array('data' => $data, 'type' => 'td', 'setting' => 'colspan="4"')
                        ,'option' => array('type' => 'tr', 'setting' => '')
                      );
        $tableArr[] = array(
                        array('data' => 'no', 'type' => 'td', 'setting' => ''),
                        array('data' => 'file', 'type' => 'td', 'setting' => ''),
                        array('data' => 'class/function', 'type' => 'td', 'setting' => ''),
                        array('data' => 'arg', 'type' => 'td', 'setting' => ''),
                        'option' => array('type' => 'tr', 'setting' => '')
                      );
        foreach ($trace as $key => $row) {
            $table = array();
            $table['option' ] = array('type' => 'tr', 'setting' => '');
            foreach ($row as $k => $r) {
                $table[] = array('data' => $r, 'type' => 'td', 'setting' => '');
            }
            
            $tableArr[] = $table;
        }
        
        // テーブル化して出力
        echo CU::factoryHtmlTable($tableArr);
    }
}


/**
 * ユーティリティ ショートコール クラス
 */
class UT extends Utility
{
}
?>